<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    header {
      width: 375px;
      height: 60px;
      background-color: lightcoral;
      color: white;
      font-size: 20px;
      display: flex;
      justify-content: center;
      align-items: center;
      position: relative;
    }
    span {
      position: absolute;
      right: 20px;
      top: 50%;
      transform: translateY(-50%);
    }
  </style>
</head>
<body>
  <div id="app">
    <h2>props的校验</h2>
    <son :count="10" name="zhangsan" :age="30" sex="男" :money="1200"></son>
  </div>

  <script src="../vue3.js"></script>
  <script>

    const {createApp} = Vue;

    const Son = {
      // props: ["count", "name", "age", "sex"],
      props: {
        count: [Number, String], // 表示count既可以是Number，也可以是String
        name: {
          type: String,
          required: true
        }, // required: true，表示必填参数
        age: {
          type: Number,
          default: 20
        }, // default: 20, 表示props的默认值
        sex: {
          validator(value) {
            return ["男", "女"].includes(value)
          }
        }, // validator用于精准校验
        money: {
          validator(value) {
            return value > 1000
          }
        }
      },
      template: `
        <div>这是son子组件</div>
        <p>count: {{ count }}</p>
        <p>name: {{ name }}</p>
        <p>age: {{ age }}</p>
        <p>sex: {{ sex }}</p>
        <p>骏哥的日工资: {{ money }}</p>
      `
    }

    const app = createApp({
      components: {
        Son
      }
    });

    app.mount("#app");
  </script>
</body>
</html>